package cn.tedu.fy.pethome.controller;

import cn.tedu.fy.pethome.pojo.dto.AdminAddNewDTO;
import cn.tedu.fy.pethome.pojo.dto.AdminLoginDTO;

import cn.tedu.fy.pethome.security.LoginPrincipal;
import cn.tedu.fy.pethome.service.IAdminService;
import cn.tedu.fy.pethome.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admins")
@Slf4j
@Api(tags = "管理员模块")
public class AdminController {

    @Autowired
    private IAdminService adminService;

    //添加业务,最高管理员可以添加
    @PostMapping("/add")
    @ApiOperation("添加管理员")
    public JsonResult addNew(AdminAddNewDTO adminAddNewDTO){
        log.debug("AdminController接收到的需要添加的管理员信息为{}",adminAddNewDTO);
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }



    //登录业务
    @PostMapping("/login")
    @ApiOperation("管理员登陆")
    public JsonResult login(@RequestBody AdminLoginDTO admin){
        log.debug("接收到的请求正在登录的管理员信息为{}",admin);
        String jwt = adminService.login(admin);
        return JsonResult.ok(jwt);
    }


}
